package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.CRMLibraryListData;

import java.util.ArrayList;

/**
 * Created by Megan on 16/8/10.
 */
public class CRMClientListAdapter extends BaseAdapter {

    private ArrayList<CRMLibraryListData> mDatas;
    private Context mContext;
    private LayoutInflater mInflater;

    public CRMClientListAdapter(Context context) {
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
    }

    public void bindData(ArrayList<CRMLibraryListData> datas) {
        mDatas = datas;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas == null ? null : mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        CRMLibraryListData data = mDatas.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_crm_client_list, parent, false);
            viewHolder.clientName = (TextView) convertView.findViewById(R.id.tv_crm_client_list_name);
            viewHolder.address = (TextView) convertView.findViewById(R.id.tv_crm_client_list_address);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.clientName.setText(data.getClientName());
        viewHolder.address.setText(data.getAddress());
        return convertView;
    }

    class ViewHolder {
        private TextView clientName;
        private TextView address;
    }
}
